package changeFinal;

import java.lang.reflect.Field;

public class Change {
    public static void main(String[] args) throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException {
        Demo1 demo1 = new Demo1();
        System.out.println(demo1);
        demo1.x.string="1";
        System.out.println(demo1);
//        demo1.demo2=new Demo2("2");
        System.out.println("======================================");

        Field x = demo1.getClass().getDeclaredField("x");

        x.setAccessible(true);

        x.set(demo1,new Demo2("2"));

        System.out.println(demo1);
    }
}
